package org.sundatagroup.aurora.show.entity.status;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

/**
 * <p>向前台发送的展示的状态信息封装类, 播放中
 * </p>
 * 
 * @version 0.1.1
 * 
 * @author lui
 * @date 2018-03-28
 * @since 0.1
 */
public class PlayingStatus implements IStatusEntity {

	private String sid;		  //屏幕编号
	//以下为新加入变量
	//private String status;	//单个状态
	private int moduleIndex;  //正在播放的module序号
	
	/**
	 * 模块名. 可能为空
	 */
	private String moduleName;//模块名
	private int moduleLength; //当前要播放的module总数
	private int sceneIndex;   //场景序号
	private int sceneLength;  //当前module的scene总数
	private int pid;		  //project编号

	public PlayingStatus(){}
	public PlayingStatus(int pid,String sid){
		this.pid = pid;
		this.sid = sid;
	}
	
	PlayingStatus(JsonObject jo) {
		sid = jo.get("sid").getAsString();
		pid = jo.get("pid").getAsInt();
		moduleIndex = jo.get("moduleIndex").getAsInt();
		
		JsonElement elem = jo.get("moduleName");
		if (elem.isJsonPrimitive()) {
			moduleName = elem.getAsString();
		}
		
		moduleLength = jo.get("moduleLength").getAsInt();
		sceneIndex = jo.get("sceneIndex").getAsInt();
		sceneLength = jo.get("sceneLength").getAsInt();
	}

	public void updataStatus(String sid,int moduleIndex,String moduleName,int moduleLength,int sceneIndex,int sceneLength){
		this.sid = sid;
		this.moduleIndex = moduleIndex;
		this.moduleName = moduleName;
		this.sceneIndex = sceneIndex;
		this.sceneLength = sceneLength;
	}

	public int getPid() {
		return pid;
	}

	public void setPid(int pid) {
		this.pid = pid;
	}

	public String getSid() {
		return sid;
	}

	public void setSid(String sid) {
		this.sid = sid;
	}

	public final DisplayStatus getStatus() {
		return DisplayStatus.PLAYING;
	}

	public int getModuleIndex() {
		return moduleIndex;
	}

	public void setModuleIndex(int moduleIndex) {
		this.moduleIndex = moduleIndex;
	}

	public String getModuleName() {
		return moduleName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}

	public int getModuleLength() {
		return moduleLength;
	}

	public void setModuleLength(int moduleLength) {
		this.moduleLength = moduleLength;
	}

	public int getSceneIndex() {
		return sceneIndex;
	}

	public void setSceneIndex(int sceneIndex) {
		this.sceneIndex = sceneIndex;
	}

	public int getSceneLength() {
		return sceneLength;
	}

	public void setSceneLength(int sceneLength) {
		this.sceneLength = sceneLength;
	}
	
	@Override
	public JsonObject toJson() {
		JsonObject jo = new JsonObject();
		jo.addProperty("status", "playing");
		jo.addProperty("sid", sid);
		jo.addProperty("pid", pid);
		jo.addProperty("moduleIndex", moduleIndex);
		jo.addProperty("moduleName", moduleName);
		jo.addProperty("moduleLength", moduleLength);
		jo.addProperty("sceneIndex", sceneIndex);
		jo.addProperty("sceneLength", sceneLength);
		
		return jo;
	}
	
	@Override
	public String toString() {
		return "PlayingStatus " + toJson().toString();
	}
}
